<template>
	<view class="me">
		<view class="status_bar"></view>
		<view class="logo">
			<img src="static/images/logo.png" alt="" />
		</view>
		<view class="name" @click="navOfficialNet">
			<text>ZY Player APP</text>
		</view>
		<u-cell-group>
			<u-cell-item title="云盘资源" value="查看云盘文件" :arrow="false" @click="openDrive"></u-cell-item>
			<u-cell-item title="视频解析" value="解析视频播放" :arrow="false" @click="openAnalyze"></u-cell-item>
			<u-cell-item title="播放记录" value="记录播放历史" :arrow="false" @click="openHistoryPage"></u-cell-item>
			<u-cell-item title="视频源管理" value="管理视频源数据" :arrow="false" @click="siteEdite"></u-cell-item>
			<u-cell-item title="青少年配置" value="管理青少年配置项" :arrow="false" @click="openR18Keywords"></u-cell-item>
			<u-cell-item title="清空播放记录" value="清空播放记录数据" :arrow="false" @click="clearHistory"></u-cell-item>
			<u-cell-item title="清空收藏夹" value="清空收藏夹数据" :arrow="false" @click="clearStar"></u-cell-item>
			<u-cell-item title="重置软件" value="清空所有数据, 慎点" :arrow="false" @click="resetApp"></u-cell-item>
			<u-cell-item title="版本更新" value="0.1.2" :arrow="false" @click="itemClickEvent"></u-cell-item>
		</u-cell-group>
		<u-row v-if="false">
			<u-col :span="6">
				<u-button type="success" @click="handleSave">存储</u-button>
			</u-col>
			<u-col :span="6">
				<u-button type="success" @click="handleRead">读取</u-button>
			</u-col>
		</u-row>
		<view class="tips">
			所有资源来自网上, 该软件不参与任何制作, 上传, 储存等内容,
			禁止传播违法资源. 该软件仅供学习参考, 请于安装后24小时内删除.
		</view>
		<u-toast ref="uToast" />
		<u-modal v-model="modalShow" :content="modalContent" @confirm="resetAppconfirm" :mask-close-able="true"
			show-cancel-button @cancel="resetAppCancel"></u-modal>
	</view>
</template>

<script>
	import db from "@/utils/database.js"
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				modalShow: false,
				modalContent: ''
			};
		},
		created() {},
		methods: {
			openDrive() {
				uni.navigateTo({
					url: '/pages/drive/drive',
					fail: (err) => {
						console.log(err)
					}
				})
				// this.$u.route({ url: '/pages/drive/drive' });
			},
			openAnalyze() {
				this.$u.route({ url: '/pages/analyze/analyze' });
			},
			openHistoryPage() {
				this.$u.route({ url: '/pages/history/history' });
			},
			siteEdite() {
				this.$u.route({ url: '/pages/site/site' });
			},
			openR18Keywords() {
				this.$u.route({ url: '/pages/r18Keywords/r18Keywords' });
			},
			async clearHistory() {
				this.$u.vuex('settings.history', [])
				this.$refs.uToast.show({ title: '清空播放数据成功', type: 'success', duration: '2300' })
			},
			async clearStar() {
				this.$u.vuex('settings.favorite', [])
				this.$refs.uToast.show({ title: '清空收藏夹数据成功', type: 'success', duration: '2300' })
			},
			async resetApp() {
				this.modalContent = '重置软件会清空：收藏夹数据，历史记录，导入的视频源等。恢复默认设置，以及默认的视频源。'
				this.modalShow = true
			},
			async resetAppconfirm() {
				uni.clearStorageSync()
				// #ifdef APP-PLUS
				uni.showModal({
					title: '重置成功',
					content: '点击确定重启软件',
					showCancel: false,
					success: () => {
						plus.runtime.restart()
					}
				})

				// #endif
				this.modalShow = false
				// #ifdef H5
				this.$refs.uToast.show({ title: '软件重置成功', type: 'success', duration: '2300' })
				// #endif
			},
			resetAppCancel() {
				this.modalShow = false
			},
			navOfficialNet() {
				let url = 'http://zyplayer.fun/'
				// #ifdef APP-PLUS
				plus.runtime.openURL(url)
				// #endif
				// #ifdef H5
				window.open(url)
				// #endif
			},
			itemClickEvent(item) {
				let url = 'https://gitee.com/haven5/ZY-Player-APP'
				// #ifdef APP-PLUS
				plus.runtime.openURL(url)
				// #endif
				// #ifdef H5
				window.open(url)
				// #endif
			},
			handleSave() {
				let time = this.$u.timeFormat(new Date(), 'hh:MM:ss')
				this.$u.vuex('settings.time', time)

				this.$u.toast('Save success！')
			},
			handleRead() {
				this.$u.toast(this.settings.time)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.me {
		.status_bar {
			height: var(--status-bar-height);
			width: 100%;
		}

		.logo {
			margin-top: 20px;
			width: 100%;
			text-align: center;

			img {
				width: 26%;
			}
		}

		.name {
			margin-top: 10px;
			text-align: center;
			font-size: 20px;
			margin-bottom: 10px;
		}

		.tips {
			color: #ff4445;
			padding: 15px;
			min-height: 400upx;
		}
	}
</style>